unit UntConf;

interface

uses
  Forms,IniFiles;

type
  TConfig = class(TObject)
  private
    const REPORTSS: String = 'Report';      //Report
    var vFIni:TIniFile;
    class var _instance: TConfig;
    constructor Create(fileName: String);
    function GetAddress: string;
    function GetDBUserName: string;
    function GetReportModal: Integer;
    function Getserverip: string;
    function GetstoreCode: string;
    function GetShopName: String;
    function GetstoreCodeList: string;
  public
    class function getAppDir: String;
    class function Instance: TConfig;
    property Address: string read GetAddress;
    property DBUserName: string read GetDBUserName;
    property ReportModal: Integer read GetReportModal;
    property serverip: string read Getserverip;
    property storeCode: string read GetstoreCode;
    property ShopName: String read GetShopName;
    property storeCodeList: string read GetstoreCodeList;
  end;

implementation

uses
  SysUtils;



constructor TConfig.Create(fileName: String);
begin
  inherited Create();
  vFIni := TIniFile.Create(fileName);
end;

function TConfig.GetAddress: string;
begin
  Result := vFIni.ReadString(REPORTSS,'Address','');
end;

class function TConfig.getAppDir: String;
begin
  Result := ExtractFileDir(Application.ExeName);
end;

function TConfig.GetDBUserName: string;
begin
  Result := vFIni.ReadString(REPORTSS,'DBUserName','root');
end;

function TConfig.GetReportModal: Integer;
begin
  Result := vFIni.ReadInteger(REPORTSS,'ReportModal',0);
end;

function TConfig.Getserverip: string;
begin
  Result := vFIni.ReadString(REPORTSS,'serverIP','127.0.0.1');
end;

function TConfig.GetstoreCode: string;
begin
  Result := vFIni.ReadString(REPORTSS,'storeCode','');
end;

function TConfig.GetShopName: String;
begin
  Result := vFIni.ReadString(REPORTSS,'shopName','');
end;

function TConfig.GetstoreCodeList: string;
begin
  Result := vFIni.ReadString(REPORTSS,'storeCodeList','');
end;

class function TConfig.Instance: TConfig;
var filename :String;
begin
  if _instance=nil then
  begin
    filename :=  getAppDir +'\conf\pos.ini';
    _instance := TConfig.Create(filename);
  end;
  Result := _instance;
end;

end.
